package com.bw.repair

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.bw.lib_base.mvvm.BaseActivity
import com.bw.repair.databinding.ActivityRepairDetailBinding
import dagger.hilt.android.AndroidEntryPoint
import java.text.SimpleDateFormat

@AndroidEntryPoint
@Route(path = "/repair/RepairDetailActivity")
class RepairDetailActivity : BaseActivity<ActivityRepairDetailBinding,RepairViewModel>() {
    @Autowired
    lateinit var rid: String
    lateinit var repairItem : RepairBeanItem
    val sdf = SimpleDateFormat("YYYY-MM-dd HH:mm:ss")
    override fun initView() {

        ARouter.getInstance().inject(this)
        viewModel.getDetail(rid.toInt())

        binding.repDetailOk.setOnClickListener {
            repairItem.processingStatus = "处理中"
            viewModel.updateRepair(rid.toInt(),repairItem)
        }

        binding.repDetailRefause.setOnClickListener {
            repairItem.processingStatus = "已完成"
            viewModel.updateRepair(rid.toInt(),repairItem)
            binding.repDetailGroup.visibility = View.GONE
        }
    }

    override fun initData() {
        viewModel.repairByIdData.observe(this){
            binding.bean = it
            repairItem = it
            if (it.processingStatus != "已完成"){
                binding.repDetailGroup.visibility = View.VISIBLE
            }
            if (it.processingStatus == "处理中"){
                binding.repDetailProCircle2.setBackgroundResource(R.drawable.shape_solide_darkgreen)
            }
            if (it.processingStatus == "已完成"){
                binding.repDetailProCircle2.setBackgroundResource(R.drawable.shape_solide_darkgreen)
                binding.repDetailProCircle3.setBackgroundResource(R.drawable.shape_solide_darkgreen)
            }
        }

        viewModel.updateData.observe(this){
            binding.bean = it
            if (it.processingStatus != "已完成"){
                binding.repDetailGroup.visibility = View.VISIBLE
            }
            if (it.processingStatus == "处理中"){
                binding.repDetailProCircle2.setBackgroundResource(R.drawable.shape_solide_darkgreen)
            }
            if (it.processingStatus == "已完成"){
                binding.repDetailProCircle2.setBackgroundResource(R.drawable.shape_solide_darkgreen)
                binding.repDetailProCircle3.setBackgroundResource(R.drawable.shape_solide_darkgreen)
            }
        }
    }
}